layui.use(['layer', 'form', 'table', 'admin', 'ax', 'func', 'tree'], function () {
    var $ = layui.$;
    var layer = layui.layer;
    var form = layui.form;
    var table = layui.table;
    var $ax = layui.ax;
    var admin = layui.admin;
    var func = layui.func;
    var tree = layui.tree;

    /**
     * 系统管理--消息管理
     */
    var Notice = {
        tableId: "noticeTable" ,   //表格id
        condition: {
            deptId: ""
        }
    };
    /**
     * 检索店名
     */
    var languageAjax = new $ax(Feng.ctxPath + "/btyWage/getDm");
    var languageResult = languageAjax.start();
    $.each(languageResult, function (index, val) {
        $("#dm").append("<option value='" + val.dm + "'>" + val.dm + "</option>");
    });
    form.render('select');

    /**
     * 初始化表格的列
     */
    Notice.initColumn = function () {
        return [[
            // {type: 'checkbox'},
            {field: 'id', align: "left", hide: true, sort: true, title: 'id'},
            {field: 'xm', align: "left", sort: false, title: '姓名',width:110},
            {field: 'tel', align: "left", sort: false, title: '手机号',width:110},
            {field: 'yhk', align: "left", sort: false, title: '银行卡'},
            {field: 'cardName', align: "left", sort: false, title: '所属银行'},
            {field: 'hh', align: "left", sort: false, title: '银行行号'},
            {field: 'yhkStatus', align: "left", sort: false, title: '银行卡状态',width:100},
            {field: 'dm', align: "left", sort: false, title: '店铺名'},
            {field: 'zw', align: "left", sort: false, title: '职务'},
            {align: 'center', toolbar: '#tableBar', title: '操作'}
        ]];

    };
    // 重置按钮事件
    $('#btnReset').click(function () {
        $('input').val('');
        $("#dm").val('');
        $("#yhkStatus").val('');
        form.render();
    });
    /**
     * 点击查询按钮
     */
    Notice.search = function () {
        var queryData = {};
        queryData['xm'] = $("#xm").val();
        queryData['tel'] = $("#tel").val();
        queryData['dm'] = $("#dm").val();
        queryData['yhkStatus'] = $("#yhkStatus").val();
        table.reload(Notice.tableId, {
            where: queryData, page: {curr: 1}
        });
    };


    /**
     * 点击修改
     *
     * @param data 点击按钮时候的行数据
     */
    Notice.onEditNotice = function (data) {
        func.open({
            height: 500,
            width:'800px',
            title: '修改银行卡',
            content: Feng.ctxPath + "/alipay/edit?id=" + data.id,
            tableId: Notice.tableId
        });
    };

    // 渲染表格
    var tableResult = table.render({
        elem: '#' + Notice.tableId,
        url: Feng.ctxPath + '/alipay/list',
        page: true,
        height: "full-59",
        cellMinWidth: 100,
        limit: 20,
        cols: Notice.initColumn(),
    });


    Notice.btnExport = function () {
        var checkRows = table.checkStatus(Notice.tableId);
        if (checkRows.data.length === 0) {
            // Feng.error("请选择要导出的数据");

            //获取导出Excel的数据
            var ajax = new $ax(Feng.ctxPath + "/alipay/export");
            ajax.set("yhkStatus", $("#yhkStatus").val());
            var result = ajax.start();
            var lists=result;
            for (index in lists) {
                var yhk = lists[index].yhk;
                var hh = lists[index].hh;
                lists[index].yhk = yhk + "\t";
                if (hh != undefined){
                    lists[index].hh = hh + "\t";
                }

            }
            table.exportFile(tableResult.config.id, lists, 'xls');

        } else {
            table.exportFile(tableResult.config.id, checkRows.data, 'xls');
        }
    };

    // 导出按钮点击事件
    $('#btnExport').click(function () {
        Notice.btnExport();
    });


    // 搜索按钮点击事件
    $('#btnSearch').click(function () {
        Notice.search();
    });

    // 添加按钮点击事件
    $('#btnAdd').click(function () {
        Notice.openAddNotice();
    });


    // 工具条点击事件
    table.on('tool(' + Notice.tableId + ')', function (obj) {
        var data = obj.data;
        var layEvent = obj.event;

        if (layEvent === 'edit') {
            Notice.onEditNotice(data);
        } else if (layEvent === 'delete') {
            Notice.onDeleteNotice(data);
        }
    });
});
